﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;

namespace JXT.PrimaryKey.Batman.Domain.Repositories.SqlServer.Expressions {
    internal static class ParameterFactory {
        private static readonly DbProviderFactory factory
            = SqlClientFactory.Instance;

        public static IDataParameter Create(string name) {
            return Create(name, null, null, null);
        }

        public static IDataParameter Create(string name, object value) {
            return Create(name, null, null, value);
        }

        public static IDataParameter Create(string name, DbType type, object value) {
            return Create(name, type, null, value);
        }

        public static IDataParameter Create(string name, DbType? type, int? size, object value) {
            var result = factory.CreateParameter();
            result.ParameterName = name;
            result.Value = value;
            if (type != null)
                result.DbType = type.Value;
            if (size != null)
                result.Size = size.Value;
            return result;
        }
    }
}
